<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注冊</title>
</head>
<body>
    <form action="/Home/User/doregister" method="post" onsubmit="return false;">
        账号：<input type="text" name="username" value="" id="uname" onkeyup="showHit(this.value)"><span id="ts"></span><br><br>
        密码：<input type="password" name="password" value="" id="passw"><br><br>
        手机号：<input type="text" name="phone" value="" id="tel"><br><br>
        <button id="zhuce">注册</button>

    </form>
</body>
<script type="text/javascript" src="/Public/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
//    alert($);
    function showHit(str){
        var xmlhttp;
//        alert(str);
        if(str.length == 0)
        {
            $('#ts').html('');
            return;
        }
        if(str.length < 5)
        {
            $('#ts').html('账号不能小于5位');
            return;
        }
        if(window.XMLHttpRequest)
        {
            xmlhttp = new XMLHttpRequest();
        }else{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function()
        {
            if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
            {
                $('#ts').html(xmlhttp.responseText);
            }

        }
        xmlhttp.open('GET','/Home/User/register?uname='+str,true);
        xmlhttp.send();
    }
    $('#zhuce').on('click',function(){
        var name = $('#uname').val();
        var passw = $('#passw').val();
        var phone = $('#tel').val();
        if(name == '')
        {
            alert('账号不能为空');
        }else if(passw == '')
        {
            alert('密码不能为空');
        }else if(phone == '')
        {
            alert('手机号不能为空');
        }
//        var num = phone.substr(0,3);
        var reg = /(1[3-9]\d{9}$)/;
        if(!reg.test(phone))
        {
            alert('请输入正确格式的手机号码!');
        }
        //ajax请求
        var url = '/Home/User/doregister';
        var data= {'username':name,'password':passw,'phone':phone};
        $.post(url,data,function(res){
             if(res.status == 0){
                alert(res.content);
            }else if(res.status == 2)
            {
                alert(res.content);
            }


        },'json')

    });
</script>
</html>